const path = require('path')
const cors = require('koa2-cors')
const koaBody = require('koa-body')
// const static = require('koa-static-server')

module.exports = app => {
  // app.use(static({
  //   rootDir: path.resolve(__dirname, '../', 'resources/upload'),
  //   rootPath: '/upload'
  // }))
  // app.use(static({
  //   rootDir: path.resolve(__dirname, '../', 'resources/images'),
  //   rootPath: '/images'
  // }))
  app.use(cors())
  app.use(koaBody({
    multipart: true, // 支持文件上传
    formidable:{
      uploadDir: path.resolve(__dirname, 'resources/upload/'), // 设置文件上传目录
      keepExtensions: true,    // 保持文件的后缀
      maxFieldsSize: 2 * 1024 * 1024, // 文件上传大小限制
      onFileBegin: (name, file) => { // 文件上传前的设置
        console.log(`name: ${name}`)
        // console.log(file);
      }
    }
  }))
}
